package com.spring_hibernate;

import javax.sql.DataSource;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class BookDaoImplTest {
	public static ApplicationContext context=null;
	private BookService bookService=null;
	    
//    {
//         context= new ClassPathXmlApplicationContext("applicationContext.xml");  
//         bookService=(BookService) context.getBean("bookService");
//    }
    @Test
    public void test()
    {
        DataSource dataSource=(DataSource) context.getBean(DataSource.class);
        System.out.println(dataSource);
    }
    @Test
    public void test2()
    {
    	context= new ClassPathXmlApplicationContext("applicationContext.xml");  
        bookService=(BookService) context.getBean("bookService");
    	String bookName=bookService.findBookById(1);
        System.out.println(bookName);
    }
    
    @Test
    public void test3()
    {
    	context= new ClassPathXmlApplicationContext("applicationContext.xml");  
        bookService=(BookService) context.getBean("bookService");
    	bookService.saveBook(new Book(2, "android源码分析"));
    }
}
